package com.imooc.framework.atomic;

public class VolatileDemo implements Runnable{

    private static volatile boolean initialized = false;
    @Override
    public void run() {
        if(initialized == false){
            initialized = true;
         System.out.println(Thread.currentThread().getName() + " init success");
        } else {
            System.out.println(Thread.currentThread().getName() + " cas 失败");
        }
    }

    public static void main(String[] args) {
        VolatileDemo volatileDemo = new VolatileDemo();
        for (int i = 0; i < 100; i++) {
            new Thread(volatileDemo).start();
        }
    }
}
